package com.meitianhui.convenitenbuy.module.store.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.store.model.DskStoreDetailBean;

import java.util.List;

/**
 * Created by Administrator on 2017/11/22.
 */

public class OneLotteryDskAdapter extends BaseQuickAdapter<DskStoreDetailBean.DskStoreDetailItemBean, BaseViewHolder> {
    private Context mContext;

    public OneLotteryDskAdapter(Context context, @Nullable List<DskStoreDetailBean.DskStoreDetailItemBean> data) {
        super(R.layout.item_one_lottery_dsk, data);
        mData = data;
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, DskStoreDetailBean.DskStoreDetailItemBean item) {
        String s_time = item.getCreated_date();
        if (!TextUtils.isEmpty(s_time)) {
            String[] d_time = s_time.split(" ");
            if (d_time.length == 2) {
                s_time = d_time[0] + "\n" + d_time[1];
            }
            helper.setText(R.id.oyb_item_details_time, s_time);
        }

        String s_code = item.getDraw_code();
        if (!TextUtils.isEmpty(s_code)) {
            TextView number = helper.getView(R.id.oyb_item_details_no);
            number.setText(s_code);
            String status = item.getStatus();
            if (status.equals("exchanged") || status.equals("win")) {
                number.setTextColor(mContext.getResources().getColor(R.color.red));
            } else {
                number.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
            }
        }

        String s_store_name = item.getNick_name().trim();
        String s_mobile = item.getMobile();
        if (!TextUtils.isEmpty(s_mobile)) {
            if (s_mobile.length() == 11) {
                s_mobile = s_mobile.substring(0, 3) + "****" + s_mobile.substring(7, s_mobile.length());
            }
            helper.setText(R.id.oyb_item_details_name, TextUtils.isEmpty(s_store_name) ? s_mobile : s_mobile + "(" + s_store_name + ")");
        }
    }


}
